<?php

namespace App\Providers;

use Illuminate\Database\Events\StatementPrepared;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use PDO;

class AppServiceProvider extends ServiceProvider
{
  /**
   * Register any application services.
   */
  public function register(): void
  {
    //
  }

  /**
   * Bootstrap any application services.
   */
  public function boot(): void
  {
    // 让 DB 查询以数组的方式返回数据
    Event::listen(StatementPrepared::class, function ($event) {
      $event->statement->setFetchMode(PDO::FETCH_ASSOC);
    });
  }
}
